import Vue from 'vue';
import Router from 'vue-router';
import { routes as address } from '@/router/address';
import { routes as bridal } from '@/router/bridal';
import { routes as feedback } from '@/router/feedback';
import { routes as home } from '@/router/home';
import { routes as manage } from '@/router/manage';
import { routes as mall } from '@/router/mall';
import { routes as member } from '@/router/member';
import { routes as merchant } from '@/router/merchant';
import { routes as order } from '@/router/order';
import { routes as partner } from '@/router/partner';
import { routes as pkg } from '@/router/pkg';
import { routes as platform } from '@/router/platform';
import { routes as product } from '@/router/product';
import { routes as rebate } from '@/router/rebate';
import { routes as shop } from '@/router/shop';
import { routes as staff } from '@/router/staff';
import { routes as user } from '@/router/user';
import { routes as utils } from '@/router/utils';
import { login, setTitle, setNavigationBar, tryCheckVersionUpdate } from './hook';

Vue.use(Router)

export function createRouter() {
    const router = new Router({
        mode: 'history',
        routes: [],
    });

    const routeList = [
        address,
        bridal,
        feedback,
        home,
        manage,
        mall,
        member,
        merchant,
        order,
        partner,
        pkg,
        platform,
        product,
        rebate,
        shop,
        staff,
        user,
        utils,
    ];

    routeList.forEach((routes) => {
        router.addRoutes(routes);
    });

    router.beforeEach(login);
    router.afterEach(setTitle);
    router.afterEach(setNavigationBar);
    router.afterEach(tryCheckVersionUpdate);

    return router;
}

export const router = createRouter();
